package com.carl.study.utils;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.kv.model.GetValue;

/**
 * @program: FrameStudy
 * @description:
 * @author: Mr.Carl
 **/
public class ConsulUtils {
    public static String getConsulValue(String consulHost, int consulPort, String consulToken, String key) {
        ConsulClient client = new ConsulClient(consulHost, consulPort);
        //client.setToken(consulToken);

        Response<GetValue> response = client.getKVValue(key);
        if (response.getValue() != null) {
            return response.getValue().getDecodedValue();
        } else {
            return null;
        }
    }
}
